﻿using AspDotNet.Core7.First.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace AspDotNet.Core7.First.Controllers
{
    public class AppSettingsController : Controller
    {
        IOptions<DataBaseConnection> Settings { get; set; }
        IConfiguration Configuration { get; set; }
        public AppSettingsController(IOptions<DataBaseConnection> settings, IConfiguration configuration)
        {
            this.Settings = settings;
            this.Configuration = configuration;
        }

        public IActionResult Index()
        {
            DataBaseConnection connectionThree = new DataBaseConnection();
            Configuration.GetSection("DBConnection").Bind(connectionThree);

            DataBaseConnection connectionFour = new DataBaseConnection();
            Configuration.Bind("DBConnection", (connectionFour = new DataBaseConnection()));

            this.ViewData["Connection"] = new
            {
                ConnectionOne = Settings.Value,
                ConnectionTwo = new DataBaseConnection()
                {
                    MySqlConn = Configuration["DBConnection:MySqlConn"].ToString(),
                    SqlServerConn = Configuration.GetValue<string>("DBConnection:SqlServerConn"),
                    OracleConn = Configuration.GetSection("DBConnection")["OracleConn"],
                },
                ConnectionThree = connectionThree,
               ConnectionFour = connectionFour
            };
            return View();
        }
    }
}
